// 流程管理接口
import { ajaxService } from '@/utils/request';
import {
  Flow,
  FlowParams,
  FlowProcessParams,
  ApprovalRelease,
  ConditionType
} from './type';

const env = import.meta.env;
const baseURL = env.VITE_APP_BASE_URL;
/**
 *
 * @param data 新增流程
 * @returns
 */
export async function AddFlow(data: Flow) {
  return ajaxService<{ processId?: number }>({
    url: '/flow/process',
    method: 'post',
    baseURL,
    data
  });
}
/**
 * 获取流程列表
 * @param params
 * @returns
 */
export async function getFlowList(params: FlowParams) {
  return ajaxService<{ processList?: any }>({
    url: '/flow/process/page',
    method: 'get',
    baseURL,
    params
  });
}
/**
 * 根据APPcode和groupCode获取流程列表
 * @param params
 * @returns
 */
export async function getFlowProcessList(params: FlowProcessParams) {
  return ajaxService<{ processList?: any }>({
    url: '/flow/specified/group/process/list',
    method: 'get',
    baseURL,
    params
  });
}
/**
 * 获取所有流程
 * @returns
 */
export async function getFlowAll() {
  return ajaxService<any>({
    url: '/platform_ccc/Flow/all',
    method: 'get',
    baseURL
  });
}
export async function getFlowById(id: number) {
  return ajaxService<any>({
    url: `/flow/process/${id}`,
    method: 'get',
    baseURL
  });
}
/**
 * 编辑流程
 * @param params
 * @returns
 */
export async function editFlow(data: FlowParams) {
  return ajaxService<{ processId?: number }>({
    url: '/flow/process',
    method: 'put',
    baseURL,
    data
  });
}
/**
 * 删除流程
 * @param params
 * @returns
 */
export async function delFlowByIds(data: { ids: number[] }) {
  return ajaxService({
    url: `/flow/process`,
    method: 'delete',
    baseURL,
    data
  });
}
/**
 * 获取流程控件列表
 * @param params
 * @returns
 */
export async function getFlowCtlList(processId: number) {
  return ajaxService<{ ctlList?: any }>({
    url: `/flow/form/info/${processId}`,
    method: 'get',
    baseURL
  });
}
/**
 * 获取流程节点列表
 * @param params
 * @returns
 */
export async function getFlowPanelPointList(params: {
  processId?: number;
  ownerType?: number;
}) {
  return ajaxService<{ panelPointList?: any }>({
    url: '/flow/panel/point/list',
    method: 'get',
    baseURL,
    params
  });
}
/**
 *
 * @param data 发起审批(新增)
 * @returns
 */
export async function addApprovalRelease(data: ApprovalRelease) {
  return ajaxService({
    url: '/flow/open/remote_api/initiate/approval/flow',
    method: 'post',
    baseURL,
    data
  });
}
/**
 * 新增条件类型
 * @param data
 * @returns
 */
export async function addApprovalConditionType(data: ConditionType) {
  return ajaxService({
    url: '/flow/condition/type',
    method: 'post',
    baseURL,
    data
  });
}
/**
 * 编辑条件类型
 * @param data
 * @returns
 */
export async function editApprovalConditionType(data: ConditionType) {
  return ajaxService({
    url: '/flow/condition/type',
    method: 'put',
    baseURL,
    data
  });
}
/**
 * 获取所有审批条件类型列表
 * @param params
 * @returns
 */
export async function getFlowConditionTypeAll() {
  return ajaxService<any>({
    url: '/flow/all/condition/type/list',
    method: 'get',
    baseURL
  });
}
/**
 * 获取审批条件类型列表分页
 * @param params
 * @returns
 */
export async function getFlowConditionTypeList(params: {
  pageNumber: number;
  pageSize: number;
  search?: string;
}) {
  return ajaxService<any>({
    url: '/flow/condition/type/page',
    method: 'get',
    baseURL,
    params
  });
}
/**
 * 审批条件类型名称查重
 * @param params
 * @returns
 */
export async function conditionTypeCheck(params: { typeName?: string }) {
  return ajaxService<any>({
    url: '/flow/condition/type/repeatability/check',
    method: 'get',
    baseURL,
    params
  });
}
/**
 * 删除流程
 * @param params
 * @returns
 */
export async function delFlowConditionTypeByIds(data: { ids: number[] }) {
  return ajaxService({
    url: `/flow/condition/type`,
    method: 'delete',
    baseURL,
    data
  });
}
/**
 * 通过缩略词获取流程列表
 * @param businessAcronyms 缩略词
 * @returns
 */
export async function getProcessByAcronym(businessAcronyms: string) {
  return ajaxService<any>({
    url: `/flow/process/list/${businessAcronyms}`,
    method: 'get',
    baseURL
  });
}
